<?php 
$province_id = 0;
$city_id = 0;
$county_id = 0;
$base_id = 0;
$ops_provinces = array();
$ops_citys = array();
$ops_countys = array();
$ops_bases = array();
$ops_levels = array();
$bases = array();
$provinces = MtsysProvince::model()->findAll();
$citys = MtsysCity::model()->findAll();
$countys = MtsysCounty::model()->findAll();
$bases = MtsysBase::model()->findAll();
if(empty($provinces)){
	echo "<script>alert('没有可选单位,请先创建单位,再添加用户');window.location.replace('index.php?r=unit/admin');</script>";	
}else{
	$ops_provinces = CHtml::listData($provinces,'PROVINCE_ID','PROVINCE_NAME');
	$ops_provinces[0] = "请选择省级";
	$ops_citys[0] = "请选择市级";
	$ops_countys[0] = "请选择区县级";
	//$ops_bases[0] = "请选择站点";
	$ops_levels[1] = '省级';
}
if(!empty($citys)){
	$ops_levels[2] = '市级';	
}
if(!empty($countys)){
	$ops_levels[3] = '区县级';
}
if(!empty($bases)){
	$ops_levels[4] = '站点';	
}
?>
<?php 
/* 
<label>
<?php echo CHtml::activeLabelEx($model,'superuser'); ?>
<?php 
echo CHtml::activeDropDownList($model,'superuser',User::itemAlias('AdminStatus'),
	array(
		'onchange'=>'UnitSelector.showUnit(this)',
	)); 
?>
</label>
<br/>
*/ 
?>
<label id="select_unit_level">
<?php echo CHtml::activeLabelEx($model,'unit_level'); ?>
<?php 
echo CHtml::activeRadioButtonList($model,'unit_level',$ops_levels, array('template'=>'{input}{label}','separator'=>'','onclick'=>'')); 
if(count($ops_levels) < 4){
	echo '<span style="color:red;">若要添加下级需要补全单位 <a href="/index.php?r=unit/admin">添加下属单位</a></span>';	
}
?>
</label>
<br/>
<div id="select_unit_id" style="display:none;">
<?php 
echo CHtml::activeLabel($model,'unit_id');
echo CHtml::dropDownList('User[PROVINCE_ID]',$province_id, $ops_provinces ,array(
	'ajax' => array(
		'type'=>'POST',
		'url'=> array('/mtsysBase/getCitys'),
		'update'=>'#CITY_ID',
		'data'=>array('PROVINCE_ID'=>'js:$("#PROVINCE_ID").val()'),
	),
	'id'=>'PROVINCE_ID',			
));
echo CHtml::dropDownList('User[CITY_ID]',$city_id, $ops_citys, array(
	'ajax' => array(
		'type'=>'POST',
		'url'=> array('/mtsysBase/getCountys'),
		'update'=>'#COUNTY_ID',
		'data'=>array('CITY_ID'=>'js:$("#CITY_ID").val()'),
	),
	'id'=>'CITY_ID',
	'style'=>'display:none;',
));
echo CHtml::dropDownList('User[COUNTY_ID]',$county_id, $ops_countys, array(
	'ajax' => array(
		'type'=>'POST',
		'url'=> array('/mtsysBase/getBasesCK'),
		'update'=>'#User_BASE_ID',
		'data'=>array('COUNTY_ID'=>'js:$("#COUNTY_ID").val()'),
	),
	'id'=>'COUNTY_ID',
	'style'=>'display:none;',
));

echo CHtml::checkBoxList('User[BASE_ID]',$base_id, $ops_bases, array(
	'id'=>'BASE_ID',
	'style'=>'display:none;',
));

?>
</div>